package com.yn.xr.common.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class StringTypeUtil {
	
	public static int strToInt(String paramStr, int defVal){
		defVal =(int) defVal;
		try{
			defVal = Integer.parseInt(paramStr);
		}catch(Exception e){
		}
		return defVal;
		
	}
	
	public static long strToLong(String paramStr, long defVal){
		defVal = defVal;
		try{
			defVal = Long.parseLong(paramStr);
		}catch(Exception e){
		}
		return defVal;
	}
	
	public static float strToFloat(String paramStr, float defVal){
		defVal = defVal;
		try{
			defVal = Float.parseFloat(paramStr);
		}catch(Exception e){
			
		}
		return defVal;
	}
	
	public static double strToDouble(String paramStr, double defVal){
		defVal = defVal;
		try{
			defVal = Double.parseDouble(paramStr);
		}catch(Exception e){
			
		}
		return defVal;
	}
	
	public static short strToShort(String paramStr, short defVal){
		defVal = defVal;
		try{
			defVal = Short.parseShort(paramStr);
		}catch(Exception e){
			
		}
		return defVal;
	}
	
	public static boolean strToBoolean(String paramStr, boolean defVal){
		defVal = defVal;
		try{
			defVal = Boolean.parseBoolean(paramStr);
		}catch(Exception e){
			
		}
		return defVal;
	}
	
	public static Date strToDate(String paramStr, String dateFormat, Date defVal){
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		if((dateFormat != null)&& !(dateFormat.isEmpty())){
			sdf = new SimpleDateFormat(dateFormat);
		}
		defVal = defVal;
		try {
			defVal = sdf.parse(paramStr);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return defVal;
	}
	
	public static Date strToDate2(String paramStr, String dateFormat, Date defVal){
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		if((dateFormat != null)&& !(dateFormat.isEmpty())){
			sdf = new SimpleDateFormat(dateFormat);
		}
		defVal = defVal;
		try {
			defVal = sdf.parse(paramStr);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return defVal;
	}
	public static String dateToStr(Date paramDate, String dateFormat, String defVal){
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dddd HH:mm:ss");
		if((dateFormat != null) && !(dateFormat.isEmpty())){
			sdf = new SimpleDateFormat(dateFormat);
		}
		defVal = defVal;
		try{
			defVal = sdf.format(paramDate);
		}catch(Exception e){
			
		}
		return defVal;
	}
	
	public static String strToStr(String paramStr, String defVal){
		defVal = defVal;
		if((paramStr != null) && !(paramStr.isEmpty())){
			defVal = paramStr;
		}
		return defVal;
	}
}
